package com.yanqu.road.server.cmd.assistant.assistantSkin;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.assistant.AssistantSkinProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.assistant.AssistantSkinModule;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_ASSISTANT_CHANGE_DESKTOP, desc = "小助手更换入口形象")
public class AssistantChangeDesktopCmd extends AbstractCommand {
    private int desktopId;
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        AssistantSkinProto.AssistantChangeDesktopReqMsg reqMsg = AssistantSkinProto.AssistantChangeDesktopReqMsg.parseFrom(packet.getBytes());
        desktopId = reqMsg.getDesktopId();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = player.getModule(AssistantSkinModule.class).changeAssistantDesktop(desktopId);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            AssistantSkinProto.AssistantChangeDesktopRespMsg.Builder respMsg = AssistantSkinProto.AssistantChangeDesktopRespMsg.newBuilder();
            respMsg.setRet(ret);
            player.sendPacket(ClientProtocol.U_ASSISTANT_CHANGE_DESKTOP, respMsg);
        }
    }
}
